<template>
  <view :class="avatarClass" :style="avatarStyle">
    <slot>
      <image
        v-if="src"
        :src="src"
        mode="aspectFill"
        :class="classNames(bem.e('image'), bem.m(shape))"
      />

      <sar-icon
        v-else
        family="sari"
        name="person"
        :root-class="bem.e('icon')"
      />
    </slot>
    <slot name="extra"></slot>
  </view>
</template>

<script>
import { mergeDefaults as _mergeDefaults, defineComponent as _defineComponent } from "vue";
import { computed } from "vue";
import { classNames, stringifyStyle, createBem } from "../../utils";
import SarIcon from "../icon/icon.vue";
import {
  defaultAvatarProps
} from "./common";
/**
 * @property {string} rootClass 组件根元素类名，默认值：-。
 * @property {StyleValue} rootStyle 组件根元素样式，默认值：-。
 * @property {'circle' | 'square'} shape 头像形状，默认值：'circle'。
 * @property {string} size 头像尺寸，默认值：-。
 * @property {string} iconSize 图标尺寸，默认值：-。
 * @property {string} src 图片类型头像的图片地址，默认值：-。
 */
export default  _defineComponent({
  components: {
    SarIcon,
  },
  ...{
    options: {
      virtualHost: true,
      styleIsolation: "shared"
    }
  },
  __name: "avatar",
  props:  _mergeDefaults({
    rootStyle: { type: [Boolean, null, String, Object, Array], required: false, skipCheck: true },
    rootClass: { type: String, required: false },
    shape: { type: String, required: false },
    size: { type: String, required: false },
    iconSize: { type: String, required: false },
    background: { type: String, required: false },
    color: { type: String, required: false },
    src: { type: String, required: false }
  }, defaultAvatarProps),
  setup(__props, { expose: __expose }) {
    __expose();
    const props = __props;
    const bem = createBem("avatar");
    const avatarClass = computed(() => {
      return classNames(bem.b(), bem.m(props.shape), props.rootClass);
    });
    const avatarStyle = computed(() => {
      return stringifyStyle(
        {
          width: props.size,
          height: props.size,
          color: props.color,
          fontSize: props.iconSize,
          background: props.background
        },
        props.rootStyle
      );
    });
    const __returned__ = { props, bem, avatarClass, avatarStyle, get classNames() {
      return classNames;
    }, SarIcon };
    return __returned__;
  }
});
</script>

<style lang="scss">
@import './index.scss';
</style>